import java.util.Scanner;
public class CinemaManagementSystem {
    private User currentUser;
    private Scanner scanner;
    public CinemaManagementSystem() {
        this.scanner = new Scanner(System.in);
    }
    public void start() {
        while (true) {
            showMainMenu();
            int choice = getIntInput("请选择操作: ");
            switch (choice) {
                case 1 -> login();
                case 2 -> System.exit(0);
                default -> System.out.println("无效选择，请重新输入");
            }
        }
    }
    private void showMainMenu() {
        System.out.println("\n影院管理系统");
        System.out.println("1. 登录");
        System.out.println("2. 退出系统");
    }
    private void login() {
        System.out.println("\n=== 用户登录 ===");
        String username = getStringInput("用户名: ");
        String password = getStringInput("密码: ");
        User user = UserRepository.getUserByUsername(username);
        if (user != null && user.getPassword().equals(password)) {
            currentUser = user;
            System.out.println("登录成功！");
            showUserMenu();
        } else {
            System.out.println("用户名或密码错误！");
        }
    }
    private void showUserMenu() {
        switch (currentUser.getUserType()) {
            case "admin" -> showAdminMenu();
            case "manager" -> showManagerMenu();
            case "front_desk" -> showFrontDeskMenu();
        }
    }
    private void showAdminMenu() {
    }

    private void showManagerMenu() {
    }

    private void showFrontDeskMenu() {
    }
    private String getStringInput(String prompt) {
        System.out.print(prompt);
        return scanner.nextLine().trim();
    }
    private int getIntInput(String prompt) {
        while (true) {
            try {
                System.out.print(prompt);
                return Integer.parseInt(scanner.nextLine().trim());
            } catch (NumberFormatException e) {
                System.out.println("请输入有效的数字！");
            }
        }
    }
    public static void main(String[] args) {
        CinemaManagementSystem system = new CinemaManagementSystem();
        system.start();
    }
}
